<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="订单编号" prop="orderNo">
                <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable maxlength="20" show-word-limit
                    style="width: 250px;" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="产品编号" prop="productNo">
                <el-input v-model="queryParams.productNo" placeholder="请输入产品编号" clearable maxlength="20" show-word-limit
                    style="width: 250px;" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="充值号码" prop="rechargeNumber">
                <el-input maxlength="11" show-word-limit v-model="queryParams.rechargeNumber" placeholder="请输入充值号码"
                    clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="企业" prop="enterpriseName">
                <el-select v-model="queryParams.enterpriseName">
                    <el-option v-for="item in enterpriseData" :key="item.id" :value="item.enterpriseName"
                        :label="item.enterpriseName">

                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <!-- <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['film:convertOrder:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['film:convertOrder:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                    @click="handleDelete" v-hasPermi="['film:convertOrder:remove']">删除</el-button>
            </el-col> -->
            <el-col :span="1.5">
                <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['film:convertOrder:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="convertOrderList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" align="center" width="55" type="index" />
            <el-table-column label="企业名称" align="center" prop="enterpriseName" min-width="200"
                :show-overflow-tooltip="true" />
            <el-table-column label="订单编号" align="center" prop="orderNo" min-width="200" :show-overflow-tooltip="true" />
            <el-table-column label="产品名称" align="center" prop="productName" min-width="150"
                :show-overflow-tooltip="true" />
            <el-table-column label="产品编号" align="center" prop="productNo" min-width="150"
                :show-overflow-tooltip="true" />
            <el-table-column label="订单流水号" align="center" prop="outTradeNo" min-width="200"
                :show-overflow-tooltip="true" />
            <el-table-column label="充值号码" align="center" prop="rechargeNumber" min-width="150"
                :show-overflow-tooltip="true" />
            <el-table-column label="订单状态" align="center" prop="status" min-width="150" :show-overflow-tooltip="true" />
            <el-table-column label="开始时间" align="center" prop="startTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="结束时间" align="center" prop="endTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="展示价格" align="center" prop="officialPrice" min-width="100"
                :show-overflow-tooltip="true" />

            <el-table-column label="结算价格" align="center" prop="consumeAmount" min-width="100"
                :show-overflow-tooltip="true" />

            <el-table-column label="微信支付价格" align="center" prop="wxOrderAmount" min-width="100"
                :show-overflow-tooltip="true" />
            <el-table-column label="备注" align="center" prop="remark" min-width="150" :show-overflow-tooltip="true" />
            <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['film:convertOrder:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['film:convertOrder:remove']">删除</el-button>
                </template>
            </el-table-column> -->
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />

        <!-- 添加或修改福利兑换订单信息对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="订单编号" prop="orderNo">
                    <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
                </el-form-item>
                <el-form-item label="产品编号" prop="productNo">
                    <el-input v-model="form.productNo" placeholder="请输入产品编号" />
                </el-form-item>
                <el-form-item label="(商户)订单流水号" prop="outTradeNo">
                    <el-input v-model="form.outTradeNo" placeholder="请输入(商户)订单流水号" />
                </el-form-item>
                <el-form-item label="充值号码" prop="rechargeNumber">
                    <el-input v-model="form.rechargeNumber" placeholder="请输入充值号码" />
                </el-form-item>
                <el-form-item label="开始时间" prop="startTime">
                    <el-date-picker clearable v-model="form.startTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择开始时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="结束时间" prop="endTime">
                    <el-date-picker clearable v-model="form.endTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择结束时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="金额" prop="consumeAmount">
                    <el-input v-model="form.consumeAmount" placeholder="请输入金额" />
                </el-form-item>
                <el-form-item label="展示价" prop="officialPrice">
                    <el-input v-model="form.officialPrice" placeholder="请输入展示价" />
                </el-form-item>
                <el-form-item label="微信支付ID,可以为null" prop="wxOrderId">
                    <el-input v-model="form.wxOrderId" placeholder="请输入微信支付ID,可以为null" />
                </el-form-item>
                <el-form-item label="微信支付价格" prop="wxOrderAmount">
                    <el-input v-model="form.wxOrderAmount" placeholder="请输入微信支付价格" />
                </el-form-item>
                <el-form-item label="用户ID" prop="userId">
                    <el-input v-model="form.userId" placeholder="请输入用户ID" />
                </el-form-item>
                <el-form-item label="删除标志" prop="delFlag">
                    <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { listConvertOrder, getConvertOrder, delConvertOrder, addConvertOrder, updateConvertOrder } from "@/api/film/convertOrder";
import { enterpriseList1 } from '@/api/film/member.js'
export default {
    name: "ConvertOrder",
    data() {
        return {
            enterpriseData: [],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 福利兑换订单信息表格数据
            convertOrderList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                status: null,
                orderNo: null,
                productNo: null,
                outTradeNo: null,
                rechargeNumber: null,
                startTime: null,
                endTime: null,
                consumeAmount: null,
                officialPrice: null,
                wxOrderId: null,
                wxOrderAmount: null,
                userId: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                status: [
                    { required: true, message: "订单状态，可选值：待支付、出票中、出票成功、出票失败、订单取消、订单完成、订单退款不能为空", trigger: "change" }
                ],
                orderNo: [
                    { required: true, message: "订单编号不能为空", trigger: "blur" }
                ],
                productNo: [
                    { required: true, message: "产品编号不能为空", trigger: "blur" }
                ],
                delFlag: [
                    { required: true, message: "删除标志不能为空", trigger: "blur" }
                ],
            }
        };
    },
    created() {
        enterpriseList1().then(res => {
            this.enterpriseData = res.rows
        })
        this.getList();
    },
    methods: {
        /** 查询福利兑换订单信息列表 */
        getList() {
            this.loading = true;
            listConvertOrder(this.queryParams).then(response => {
                this.convertOrderList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                status: null,
                orderNo: null,
                productNo: null,
                outTradeNo: null,
                rechargeNumber: null,
                startTime: null,
                endTime: null,
                consumeAmount: null,
                officialPrice: null,
                wxOrderId: null,
                wxOrderAmount: null,
                userId: null,
                delFlag: null,
                createBy: null,
                updateBy: null,
                updateTime: null,
                remark: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加福利兑换订单信息";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids
            getConvertOrder(id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改福利兑换订单信息";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateConvertOrder(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addConvertOrder(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除福利兑换订单信息编号为"' + ids + '"的数据项？').then(function () {
                return delConvertOrder(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('film/convertOrder/export', {
                ...this.queryParams,
                ids: this.ids
            }, `兑换订单_${new Date().getTime()}.xlsx`)
        }
    }
};
</script>
